// 实现内置的 Parameters 类型，而不是直接使用它，
// 用于从函数类型 T 中获取参数列表的类型。它是一个映射类型，将函数的参数类型转换为一个元组（tuple）类型

const foo = (arg1: string, arg2: number): void => {};

type MyParameters<T extends (...args: any) => any> = T extends (
  ...arg: infer P
) => any
  ? P
  : never;

type FunctionParamsType = MyParameters<typeof foo>; // [arg1: string, arg2: number]

// AppendArgument, 给函数添加一个参数
type Fn = (a: number, b: string) => number;
type AppendArgument<Fn, U> = Fn extends (...args: infer R) => infer P
  ? (...args: [...R, U]) => P
  : never;

type Result4 = AppendArgument<Fn, boolean>;
// 期望是 (a: number, b: string, x: boolean) => number

type Permutation<T, K = T> = [T] extends [never]
  ? []
  : K extends K
  ? [K, ...Permutation<Exclude<T, K>>]
  : never;

type Permuted = Permutation<"a" | "b">; // ['a', 'b'] | ['b' | 'a']
type perm = Permutation<"A" | "B" | "C">;
// ['A', 'B', 'C'] | ['A', 'C', 'B'] | ['B', 'A', 'C'] | ['B', 'C', 'A'] | ['C', 'A', 'B'] | ['C', 'B', 'A']
